package com.fc.commons.security;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class SHAUtil {
	
	private static final String SHA_KEY = "SHA";
	
	/**
	 * SHA加密
	 * @param data
	 * @return
	 */
	public static byte[] encryptSHA(byte[] data){
		MessageDigest digest = null;
		try {
			digest = MessageDigest.getInstance(SHA_KEY);
			digest.update(data);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return digest.digest();
	}
	
	/**
	 * SHA加密
	 * @param data
	 * @return
	 */
	public static String encryptSHA(String data){
		byte[] temp = encryptSHA(data.getBytes());
		return SGlobalUtil.INSTANCE.bytes2String(temp);
	}
}
